package cn.gaily.eduservice.service.impl;

import cn.gaily.eduservice.entity.EduComment;
import cn.gaily.eduservice.entity.vo.EduCommentVo;
import cn.gaily.eduservice.mapper.EduCommentMapper;
import cn.gaily.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author xuchengwei
 * @since 2021-08-09
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public List<EduCommentVo> getComment(Page<EduComment> eduCommentPage,String courseId) {
        //查找所有的一级分类
        QueryWrapper<EduComment> wrapper = new QueryWrapper<>();
        wrapper.eq("courseId",courseId);
        wrapper.eq("parent_id",0);
        baseMapper.selectPage(eduCommentPage,wrapper);
        List<EduComment> records = eduCommentPage.getRecords();
        ArrayList<EduCommentVo> arrayList = new ArrayList<>();
        for (EduComment comment :
                records) {
            EduCommentVo eduCommentVo = new EduCommentVo();
            if(!StringUtils.isEmpty(comment.getParentId())){
                EduComment eduComment = baseMapper.selectById(comment.getParentId());
                BeanUtils.copyProperties(eduComment,eduCommentVo);
            }
        }
        return null;
    }
}
